/**
 * 缓存ACTION
 */
package cn.antia.cep.page.action;

import javax.servlet.http.*;

import cn.antia.cep.common.*;
import cn.antia.cep.common.pool.*;
import cn.antia.cwin.DBConfiger;
import cn.antia.cwin.page.StrutsAction;
import cn.antia.cwin.grid.GridConfiger;
import cn.antia.cwin.window.WindowConfiger;

/**
 * @author sunkeei
 *
 */
public class UpdateCacheAction extends StrutsAction {
	private String action;
	private AntiaPool antiaPool;
	public void setAntiaPool(AntiaPool antiaPool) {
		this.antiaPool = antiaPool;
	}
	public void setAction(String action) {
		this.action = action;
	}

	protected String action() throws AntiaException {
		if(action == null || action.trim().length() < 1){
			action = "all";
		}
		if(action.equals("all")){
			updateAll(request);
		}else if(action.equals("dbConfig")){
			antiaPool.resetAllComsats();
			DBConfiger.reset();
		}else if(action.equals("gridConfig")){
			antiaPool.setGridElements(null);
			GridConfiger.reset();
		}else if(action.equals("window")){
			antiaPool.setSingleWindows(null);
			WindowConfiger.reset();
		}
		else{
			AntiaLog.error("传入了错误的参数：action:" + action);
		}
		AntiaLog.warn(new StringBuffer("IP ").append(request.getRemoteAddr()).append("强制更新了缓存。").toString());
		request.setAttribute("message", "更新缓存成功。");
		return "finished";
	}
	
	private void updateAll(HttpServletRequest request){
		antiaPool.resetAllComsats();
		DBConfiger.reset();
		antiaPool.setGridElements(null);
		GridConfiger.reset();
	}

}
